var showEnergyStatistics,goEnergyDetailsPage;
require(['highcharts', 'highcharts-more'],  function () {
	window.clear=function(){
		$("#energyStatisticsTrend").empty();
	}
	getCarEnergyDetail = function(carId, rcrdDate,fuelType) {
		$.ajaxExt({
			url: "/energyStatistics/getCarEnergyDetail.htm",
			loadMask:true,
            data: {
                carId: carId,
                reportDate: rcrdDate,
                fuelType: fuelType
            }
		}).done(function(result){
			 var daysArr=[] ;
			 var daysArr2=[] ;
			 var daysArr3=[] ;
			 var daysArr4=[] ;
			$(result).each(function(i,item) {
				
				daysArr.push([item.rcrdTimeChange , parseFloat(item.totalMile)]);
				daysArr2.push([item.rcrdTimeChange , parseFloat(item.totalEnerCons)]);
				daysArr3.push([item.rcrdTimeChange , parseFloat(item.totalOprtDura)]);
				daysArr4.push([item.rcrdTimeChange , parseFloat(item.onlineSt||0)]);
			}) 
			 console.info(daysArr4);
			$("#energyStatisticsTrend").highcharts({
				chart: {
					zoomType: 'x',
					plotBorderWidth: 1,
					marginTop: 38,
					marginLeft: 90,
					marginRight: 330
				},
				title: {
					text: ''
				},
				credits: {
					enabled: false
				},
				legend:{
					//enabled:false
				},
				tooltip: {
					shared: true,
					formatter: function () {
						var html = '时间:' + new Date(this.x-1000*60*60*8).format('yyyy-MM-dd hh:mm:ss') + '<br>';
						return html;
					},
					crosshairs: true 
				},
				xAxis: {
					tickmarkPlacement: 'on',
					type: 'datetime'
				},
				yAxis: [
	                    {
	                        min: -1,
	                        title: {
	                            text: ''
	                        },
	                        labels: {
	                            formatter: function () {
	                                if (this.value == 1) {
	                                    return '在线';
	                                } else if (this.value == 0) {
	                                    return '离线';
	                                }
	                                return '';
	                            }
	                        },
	                        minorGridLineWidth: 0,
	                        gridLineWidth: 0,
	                        alternateGridColor: null,
	                        plotBands: [{ // Light air
	                            from: 0.9,
	                            to: 1.1,
	                            color: 'rgba(68, 170, 213, 0.1)'
	                        },
	                            { // Light air
	                                from: 0,
	                                to: 0.2,
	                                color: 'rgba(68, 170, 213, 0.1)'
	                            }

	                        ]
	                    },
					{ // Primary yAxis
			            labels: {
			                format: '{value}KM',
			                style: {
			                    color: '#EA0000'
			                }
			            },
			            title: {
			                text: '里程',
			                style: {
			                    color: '#EA0000'
			                }
			            },
			            opposite: true
			        }, { // Secondary yAxis
			            title: {
			                text: '能耗',
			                style: {
			                    color: '#02DF82'
			                }
			            },
			            labels: {
			                format: '{value} L',
			                style: {
			                    color: '#02DF82'
			                }
			            },
			            opposite: true
			        },
			          { // Secondary yAxis
			            title: {
			                text: '时长',
			                style: {
			                    color: '#4572A7'
			                }
			            },
			            labels: {
			                format: '{value} 毫秒',
			                style: {
			                    color: '#9D9D9D'
			                }
			            },
			            opposite: true
			        }
				],
				series: [
					{
						data: daysArr4,
						name: '在线率',
						color: '#ca3bca',
						marker: {
							enabled: false
						}
					} ,
					{
						data: daysArr,
						name: '设备总里程变化',
						color: '#EA0000',
						yAxis: 1,
						marker: {
							enabled: false
						}
					},
					{
						data: daysArr2,
						name: '设备总能耗变化',
						color: '#02DF82',
						yAxis: 2,
						marker: {
							enabled: false
						}
					},
					{
						data: daysArr3,
						name: '设备总时长变化',
						yAxis: 3,
						color: '#9D9D9D',
						marker: {
							enabled: false
						}
					}
				]
			});
		});
    };
});